package org.cyk;

import com.cyk.HelloProto;
import com.cyk.HelloServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

public class Client2 {

    public static void main(String[] args) {
        //1.创建通信管道
        ManagedChannel managedChannel = ManagedChannelBuilder.forAddress("localhost", 9000).usePlaintext().build();
        //2.创建代理对象 stub
        try {
            HelloServiceGrpc.HelloServiceBlockingStub helloService = HelloServiceGrpc.newBlockingStub(managedChannel);
            //3.完成 RPC 调用
            //3.1 准备参数
            HelloProto.HelloListRequest request = HelloProto.HelloListRequest
                    .newBuilder()
                    .addName("cyk1")
                    .addName("cyk2")
                    .addName("cyk3")
                    .addName("cyk4")
                    .build();
            //3.2 进行 rpc 调用
            HelloProto.HelloResponse response = helloService.helloList(request);
            System.out.println("response: " + response);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            managedChannel.shutdown();
        }
    }

}
